// 引入store
import store from './store'
import { useSelector, TypedUseSelectorHook, useDispatch } from 'react-redux'
// 这里的typeof不是js的typeof.是ts的typeof返回typeof后面代码的类型
// typeof store.getState 返回store.getState的类型
// ReturnType<typeof store.getState> 返回store.getState这个函数中返回值的类型
export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch

// 定义新常量
// useAppSelector把useSelector的回调中state的类型定义好了,所以下次再写useSelector的时候,就可以直接使用useAppSelector,并且可以不用在声明state类型
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
export const useAppDispatch = () => useDispatch<AppDispatch>()
